const messageBox = document.getElementById('alert');
function confirmPassword(){
        if(document.querySelector('#confirmpwd').value!==document.querySelector('#password').value)
        {
            displayMessage('两次输入的密码不一致');
        }
        else{
            messageBox.innerText=''
            messageBox.style.backgroundColor=''
        }
}
document.querySelector('#confirmpwd').addEventListener('keyup',confirmPassword)
document.querySelector('#password').addEventListener('keyup',confirmPassword)
function getCode()
{
    const email=document.querySelector('#email').value;
    // console.log(email);
    axios({
        url:'http://47.120.4.197:8082/signIn/sendMsg',
        method:'post',
        data:{
            email
        }
    }).then(result=>{
        // console.log(result);
    }).catch(error=>{
        // console.log(error);
    })
}
function register()
{
    const email=document.querySelector('#email').value;
    const code=document.querySelector('#code').value;
    const password=document.querySelector('#password').value;
    const confirmPassword=document.querySelector('#confirmpwd').value;
    const username=document.querySelector('#username').value
    axios({
        url:'http://47.120.4.197:8082/signIn/register',
        method:'post',
        data:{
            email,
            code,
            password,
            confirmPassword,
            username,
        }
    }).then(result=>{
        if(result.data.code===80){
            location.href='../login.html';//注册成功跳到登录界面因为注册不会返回token
        }else{
            displayMessage(result.data.msg || '注册失败，请重试');
        }
        // console.log(result);
        
    }).catch(error=>{
        // console.log(error);
    })
}
function displayMessage(message) {
    messageBox.innerText = message;
    messageBox.style.backgroundColor='rgba(197, 43, 43,0.3)'
    // 显示消息框并在3秒后隐藏
    messageBox.style.display = 'block';
    if(message==='两次输入的密码不一致'){
        return
    }
    setTimeout(() => {
        messageBox.innerText=''
        messageBox.style.backgroundColor=''
    }, 2000);
  }